import { createSlice, createAsyncThunk } from '@reduxjs/toolkit';
import { findById } from '../../services/order';

export const fetchReceive = createAsyncThunk('receive/fetchReceive', async (id) => {
    let { data } = await findById(id);
    console.log(data);
    return data;
})

const receiveSlice = createSlice({
    name: "receive",
    initialState: {
        infoVisible: false,
        receiveInfo: {
            receiveName: "无",
            receivePhone: "无",
            receiveAddr: "无"
        }
    },
    reducers: {
        setInfoVisible(state, action) {
            state.infoVisible = action.payload;
        }
    },
    extraReducers(builder) {
        builder.addCase(fetchReceive.fulfilled, (state, action) => {
            state.receiveInfo = action.payload;
        })
    }
});

export const { setInfoVisible } = receiveSlice.actions;
export default receiveSlice.reducer;